home *** CD-ROM | disk | FTP | other *** search
- -- enemy.e
- -- operate the enemy ships
-
- global procedure t5rstat()
- -- task 5: Romulan status change
-
- positive_atom w
-
- w = rand(256) + rand(256) + 3
- if rstat = TRUCE then
- sounde(3,100,1)
- if truce_broken then
- truce_broken = FALSE
- msg("TRUCE BROKEN!")
- else
- msg("BASIC STATUS: HOSTILE")
- end if
- if rand(20) < 15 then
- w = w * 1.2
- ship[G_RM] = {ROMULAN_L, ROMULAN_R}
- rstat = HOSTILE
- else
- w = w * .67
- ship[G_RM] = repeat(repeat(INVISIBLE_CHAR, length(ROMULAN_L)), 2)
- rstat = CLOAKING
- end if
- else
- if rand(20) < 10 then
- sounde(2, 100, 1)
- rstat = TRUCE
- msg("BASIC STATUS: TRUCE")
- w = w * .83
- ship[G_RM] = {ROMULAN_L, ROMULAN_R}
- else
- if rstat = HOSTILE then
- w = w * .67
- rstat = CLOAKING
- ship[G_RM] = repeat(repeat(INVISIBLE_CHAR, length(ROMULAN_L)), 2)
- else
- w = w * 1.2
- rstat = HOSTILE
- ship[G_RM] = {ROMULAN_L, ROMULAN_R}
- end if
- end if
- end if
- wait[TASK_RSTAT] = w
- if scanon then
- gtext()
- end if
- end procedure
-
- procedure orient(valid_f_row row)
- -- point the ship toward its target
-
- f_row targ
- h_coord targx, rowx
- v_coord rowy
- object_type t
-
- targ = f[row][F_TARG]
- if targ = -1 then
- -- no target
- return
- end if
- targx = f[targ][F_X]
- rowx = f[row][F_X]
- rowy = f[row][F_Y]
- t = f[row][F_TYPE]
- if rowx < targx then
- write_screen(rowx, rowy, ship[t][2])
- else
- write_screen(rowx, rowy, ship[t][1])
- end if
- end procedure
-
- procedure shoot(valid_f_row row)
- -- select torpedo or phasor for enemy shot
-
- positive_int torp
- positive_atom pen
-
- shooter = row
- if f[shooter][F_TYPE] != G_BS then
- orient(shooter)
- end if
- setpt(shooter)
- torp = f[shooter][F_TORP]
- if torp > 0 and rand(4) = 1 then
- f[shooter][F_TORP] = torp - 1
- weapon(W_TORPEDO, 4000)
- else
- pen = f[shooter][F_EN] / 8
- if f[shooter][F_TYPE] = G_TH then
- tholian_phasor(pen)
- else
- weapon(W_PHASOR, pen)
- end if
- f[shooter][F_EN] = f[shooter][F_EN] - pen
- end if
- end procedure
-
-
- global procedure t6fire()
- -- task 6: select an enemy ship for firing
-
- f_row row
- positive_int rate
- f_row targ
-
- if fnext = 2 then
- return -- nobody in the quadrant
- end if
-
- row = rand(fnext-2) + ENTERPRISE -- choose a random ship
- if f[row][F_TYPE] then
- rate = f[row][F_FRATE]
- if rate > rand(256) then
- -- shoot
- if f[row][F_TYPE] = G_RM then
- if rstat != TRUCE then
- shoot(row)
- else
- if rtarg != ENTERPRISE then
- if f[rtarg][F_TYPE] != G_BS then
- shoot(row)
- end if
- end if
- end if
-
- elsif f[row][F_TYPE] = G_BS then
- targ = f[row][F_TARG]
- if targ != -1 then
- if rstat != TRUCE then
- shoot(row)
- elsif f[targ][F_TYPE] != G_RM then
- shoot(row)
- end if
- end if
-
- else
- shoot(row)
- end if
- end if
- end if
- end procedure
-
-
- global procedure t7move()
- -- select an enemy ship for moving
-
- f_row row
- positive_int mrate
- h_coord fx
- v_coord fy
- extended_h_coord xtry
- extended_v_coord ytry
- sequence uchar, schar
- positive_int t
- positive_int len
-
- if fnext = 2 then
- return -- nobody in the quadrant
- end if
-
- row = rand(fnext-2) + ENTERPRISE -- choose a random ship
- t = f[row][F_TYPE]
- if t then
- mrate = f[row][F_MRATE]
- if mrate > rand(256) then
- -- try to move
- fx = f[row][F_X]
- xtry = fx + rand(5) - 3
- len = length(ship[t][1])
- if xtry >= 2 and xtry <= HSIZE - len then
- fy = f[row][F_Y]
- ytry = fy + rand(3) - 2
- if ytry >= 1 and ytry <= VSIZE then
- schar = read_screen({xtry, len}, ytry)
- if not find(FALSE, schar = ' ' or schar = STAR) then
- sounde(13,2,1)
- uchar = f[row][F_UNDER]
- f[row][F_UNDER] = schar
- schar = read_screen({fx, len}, fy)
- write_screen(fx, fy, uchar)
- write_screen(xtry , ytry, schar)
- f[row][F_X] = xtry
- f[row][F_Y] = ytry
- end if
- end if
- end if
- orient(row)
- end if
- end if
- end procedure
-
- global procedure t8ur()
- -- task 8: print UNITS REMAIN
- msg("")
- if ur then
- printf(CRT, "%d UNITS REMAIN", ur)
- else
- printf(CRT, "%s DESTROYED", {otype[urt]})
- end if
- end procedure
-
- function add2f(object_type t, h_coord x, v_coord y)
- -- add a ship to the f array (enter it into the active quadrant)
-
- f_row targ
- valid_f_row row
- sequence c, s
-
- -- find a place in f array
- if fnext >= FROWS then
- return FALSE -- too many guys in already
- end if
- row = fstart(t)
- while row < fnext and f[row][F_TYPE] do
- row = row + 1
- if row > FROWS then
- return FALSE
- end if
- end while
-
- -- choose his target
- if t < G_RM then
- if g[qrow][qcol][G_BS] then
- for r = fb1 to fr1-1 do
- if f[r][F_TYPE] then
- targ = r
- end if
- end for
- else
- targ = ENTERPRISE
- end if
- elsif t = G_RM then
- if rtarg = -1 then
- if g[qrow][qcol][G_BS] then
- for r = fb1 to fr1-1 do
- if f[r][F_TYPE] then
- rtarg = r
- end if
- end for
- else
- rtarg = ENTERPRISE
- end if
- end if
- targ = rtarg
- else
- targ = tholian_target(row)
- end if
-
- sounde(12,2,1)
- s = stdtype[t]
- f[row][1..length(s)] = s
- f[row][F_X] = x
- f[row][F_Y] = y
- f[row][F_UNDER] = read_screen({x, length(ship[t][1])}, y)
- f[row][F_TARG] = targ
- if row = fnext then
- fnext = fnext + 1
- end if
- if x < f[ENTERPRISE][F_X] then
- c = ship[t][2]
- else
- c = ship[t][1]
- end if
- write_screen(x, y, c)
- return TRUE
- end function
-
- global procedure t10enter()
- -- enemy ship enters quadrant
-
- positive_int q
- h_coord enterx
- v_coord entery
- positive_int entert
- sequence enterc
- g_index randcol, randrow, fromcol, fromrow
-
- fromrow = qrow
- fromcol = qcol
- enterx = 2
- entery = 1
- q = rand(8)
- if q = 1 then -- left
- fromcol = gmod(qcol-1)
- entery = rand(VSIZE)
- elsif q = 2 then -- top left
- fromrow = gmod(qrow-1)
- fromcol = gmod(qcol-1)
- elsif q = 3 then -- top
- enterx = 1 + rand(HSIZE - 6) -- for now
- fromrow = gmod(qrow-1)
- elsif q = 4 then -- top right
- enterx = HSIZE - 6 -- for now
- fromrow = gmod(qrow-1)
- fromcol = gmod(qcol+1)
- elsif q = 5 then -- right
- enterx = HSIZE - 6 -- for now
- entery = rand(VSIZE)
- fromcol = gmod(qcol+1)
- elsif q = 6 then -- bottom right
- enterx = HSIZE - 6
- entery = VSIZE
- fromrow = gmod(qrow+1)
- fromcol = gmod(qcol+1)
- elsif q = 7 then -- bottom
- enterx = 1 + rand(HSIZE - 6)
- entery = VSIZE
- fromrow = gmod(qrow+1)
- else -- bottom left
- entery = VSIZE
- fromrow = gmod(qrow+1)
- fromcol = gmod(qcol-1)
- end if
- entert = 0
- if g[fromrow][fromcol][G_JM] then
- entert = G_JM
- elsif g[fromrow][fromcol][G_BK] then
- entert = G_BK
- elsif g[fromrow][fromcol][G_SK] then
- entert = G_SK
- else
- randcol = rand(G_SIZE)
- randrow = rand(G_SIZE)
- if randcol != qrow or randcol != qcol then
- if g[randrow][randcol][G_TH] then
- fromrow = randrow
- fromcol = randcol
- enterx = 1 + rand(HSIZE-6)
- entery = rand(VSIZE)
- entert = G_TH
- end if
- end if
- end if
- if entert = 0 then
- if g[fromrow][fromcol][G_RM] then
- entert = G_RM
- end if
- end if
- enterc = read_screen({enterx, 5}, entery)
- if find(TRUE, enterc != ' ' and enterc != STAR) then
- entert = 0
- end if
- if entert then
- if add2f(entert, enterx, entery) then
- g[qrow][qcol][entert] = g[qrow][qcol][entert] + 1
- g[fromrow][fromcol][entert] = g[fromrow][fromcol][entert] - 1
- if entert < G_RM then
- upg(qrow, qcol)
- gsbox(qrow, qcol)
- upg(fromrow, fromcol)
- end if
- msg("")
- printf(CRT, "%s HAS ENTERED QUADRANT", {otype[entert]})
- end if
- end if
- wait[TASK_ENTER] = rand(10) * curwarp + f[ENTERPRISE][F_EN]/rand(1000)
- end procedure
-
-